<template>
  <transition name="el-zoom-in-center">
    <div class="JNPF-preview-main">
      <div class="project-info">
        <div class="project-loop">
          <div v-loading="listLoading">
            <el-form ref="projectInfoForm" size="mini" label-width="100px" label-position="top" :model="list">
              <template v-if="!loading">
                <el-tooltip class="item" effect="dark" content="返 回 列 表" placement="left-start">
                  <el-button type="text" @click="goBack" class="closeButton">
                    <i class="ym-custom ym-custom-close-circle"></i>
                  </el-button>
                </el-tooltip>
                <el-col :span="24">
                  <jnpf-form-tip-item>
                    <JnpfText
                      :textStyle='{"color":"#1684FC","font-weight":"bold","text-decoration":"none","font-size":24,"line-height":32,"font-style":"normal","text-align":"center"}'
                      content="项目管理">
                    </JnpfText>
                    <JnpfText
                      :textStyle='{"color":"#1684FC","font-weight":"bold","text-decoration":"none","font-size":18,"line-height":32,"font-style":"normal","text-align":"left"}'
                      content="项目基础信息">
                    </JnpfText>
                  </jnpf-form-tip-item>
                </el-col>
                <el-col :span="1">
                  <el-row :gutter="30">
                    <el-col :span="24">
                      <jnpf-form-tip-item>
                        <JnpfText
                          :textStyle='{"color":"#000000","font-weight":"normal","text-decoration":"none","font-size":12,"line-height":32,"font-style":"normal","text-align":"left"}'>
                        </JnpfText>
                      </jnpf-form-tip-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="22" class="project-main">
                  <el-row :gutter="30">
                    <el-col :span="12">
                      <jnpf-form-tip-item label="企业名称">
                        <JnpfInput v-model="list.enterpriseName"
                                   placeholder="请输入" readonly clearable
                                   :style='{"width":"100%"}'>
                        </JnpfInput>
                      </jnpf-form-tip-item>
                    </el-col>
                    <el-col :span="12">
                      <jnpf-form-tip-item label="企业信用代码">
                        <JnpfInput v-model="list.enterpriseCreditCode"
                                   placeholder="请输入" readonly clearable
                                   :style='{"width":"100%"}'>
                        </JnpfInput>
                      </jnpf-form-tip-item>
                    </el-col>
                    <el-col :span="12">
                      <jnpf-form-tip-item label="所属行业">
                        <JnpfInput v-model="list.industry"
                                   placeholder="请输入" readonly clearable
                                   :style='{"width":"100%"}'>
                        </JnpfInput>
                      </jnpf-form-tip-item>
                    </el-col>
                    <el-col :span="12">
                      <jnpf-form-tip-item label="细分行业">
                        <JnpfInput v-model="list.specificIndustry"
                                   placeholder="请输入" readonly clearable
                                   :style='{"width":"100%"}'>
                        </JnpfInput>
                      </jnpf-form-tip-item>
                    </el-col>
                    <el-col :span="12">
                      <jnpf-form-tip-item label="项目类别">
                        <JnpfInput v-model="list.projectType"
                                   placeholder="请输入" readonly clearable
                                   :style='{"width":"100%"}'>
                        </JnpfInput>
                      </jnpf-form-tip-item>
                    </el-col>
                    <el-col :span="12">
                      <jnpf-form-tip-item label="预算类别">
                        <JnpfInput v-model="list.budgetType"
                                   placeholder="请输入" readonly clearable
                                   :style='{"width":"100%"}'>
                        </JnpfInput>
                      </jnpf-form-tip-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="1">
                  <el-row :gutter="30">
                    <el-col :span="24">
                      <jnpf-form-tip-item>
                        <JnpfText
                          :textStyle='{"color":"#000000","font-weight":"normal","text-decoration":"none","font-size":12,"line-height":32,"font-style":"normal","text-align":"left"}'>
                        </JnpfText>
                      </jnpf-form-tip-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="24">
                  <jnpf-form-tip-item>
                    <JnpfText
                      :textStyle='{"color":"#1684FC","font-weight":"bold","text-decoration":"none","font-size":18,"line-height":32,"font-style":"normal","text-align":"left"}'
                      content="试点项目流程">
                    </JnpfText>
                  </jnpf-form-tip-item>
                </el-col>
                <el-col :span="1">
                  <el-row :gutter="30">
                    <el-col :span="24">
                      <jnpf-form-tip-item>
                        <JnpfText
                          :textStyle='{"color":"#000000","font-weight":"normal","text-decoration":"none","font-size":12,"line-height":32,"font-style":"normal","text-align":"left"}'>
                        </JnpfText>
                      </jnpf-form-tip-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="22" class="project-flow-main">
                  <el-col :span="6">
                    <div class="flow-step">
                      <i class="el-icon-s-help"></i>
                      <label>步骤一</label>
                    </div>
                    <div class="flow-controller">
                      <label>项目管理</label>
                      <el-button type="primary"
                                 v-if="list.flowState===3 || list.flowState=== '' || list.flowState === null || list.flowState === 4"
                                 @click="updateHandle(list)">去提交
                      </el-button>
                    </div>
                    <div class="flow-result">
                      <el-alert v-if="list.flowState===3 || list.flowState === 4 || list.flowState === null "
                                title="等待提交"
                                type="warning" show-icon :closable="false"></el-alert>
                      <el-alert v-if="list.flowState===1 || list.flowState===2 || list.flowState===5" title="已提交"
                                type="success" show-icon :closable="false"></el-alert>
                    </div>
                  </el-col>
                  <el-col :span="6">
                    <div class="flow-step">
                      <i class="el-icon-s-help"></i>
                      <label>步骤二</label>
                    </div>
                    <div class="flow-controller">
                      <label>项目审核</label>
                      <el-button type="primary"
                                 v-if="list.flowState !== null"
                                 @click="updateHandle(list,list.flowState)">去查看
                      </el-button>
                    </div>
                    <div class="flow-result">
                      <el-alert title="等待审核" v-if="list.flowState===1" class="flow-ing" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="审核通过" v-if="list.flowState===2" type="success" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="审核驳回" v-if="list.flowState===3" type="error" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="流程撤回" v-if="list.flowState===4" type="warning" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="审核终止" v-if="list.flowState===5" type="success" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="等待提交" v-if="list.flowState===null" type="warning" show-icon
                                :closable="false"></el-alert>
                    </div>
                  </el-col>
                  <el-col :span="6">
                    <div class="flow-step">
                      <i class="el-icon-s-help"></i>
                      <label>步骤三</label>
                    </div>
                    <div class="flow-controller">
                      <label>进度填报</label>
                    </div>
                    <div class="flow-result">
                      <el-alert title="已完成" type="success" show-icon :closable="false"
                                v-if="checkAcceptFlowState !== undefined"></el-alert>
                      <el-alert title="进行中" class="flow-ing" show-icon :closable="false"
                                v-if="list.checkStatus==='0' && checkAcceptFlowState===undefined"></el-alert>
                    </div>
                  </el-col>
                  <el-col :span="6">
                    <div class="flow-step">
                      <i class="el-icon-s-help"></i>
                      <label>步骤四</label>
                    </div>
                    <div class="flow-controller">
                      <label>验收申请</label>
                      <el-button type="primary" @click="addOrUpdateCheckHandle()"
                                 v-if="checkAcceptTotal===0 && projectStatus"  >去发起
                      </el-button>
                      <el-button type="primary" @click="updateCheckHandle(checkAcceptList[0])"
                                 v-if="checkAcceptTotal>0 && (checkAcceptFlowState===3 || checkAcceptFlowState === 4 || checkAcceptFlowState=== '' || checkAcceptFlowState === undefined || checkAcceptFlowState === null)">
                        去提交
                      </el-button>
                      <el-button type="primary" @click="updateCheckHandle(checkAcceptList[0],checkAcceptFlowState)"
                                 v-if="checkAcceptTotal>0 &&(checkAcceptFlowState===1 || checkAcceptFlowState===2 || checkAcceptFlowState===5)">
                        去查看
                      </el-button>
                    </div>
                    <div class="flow-result">
                      <el-alert title="等待审核" v-if="checkAcceptFlowState===1" class="flow-ing" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="审核通过" v-if="checkAcceptFlowState===2" type="success" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="审核驳回" v-if="checkAcceptFlowState===3" type="error" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="流程撤回" v-if="checkAcceptFlowState===4" type="warning" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="审核终止" v-if="checkAcceptFlowState===5" type="success" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="等待提交" v-if="checkAcceptFlowState===null" type="warning" show-icon
                                :closable="false"></el-alert>
                      <el-alert title="未完成" type="error" show-icon :closable="false"
                                v-if="checkAcceptFlowState===undefined"></el-alert>
                    </div>
                  </el-col>
                </el-col>
                <el-col :span="1">
                  <el-row :gutter="30">
                    <el-col :span="24">
                      <jnpf-form-tip-item>
                        <JnpfText
                          :textStyle='{"color":"#000000","font-weight":"normal","text-decoration":"none","font-size":12,"line-height":32,"font-style":"normal","text-align":"left"}'>
                        </JnpfText>
                      </jnpf-form-tip-item>
                    </el-col>
                  </el-row>
                </el-col>
                <el-col :span="24">
                  <jnpf-form-tip-item>
                    <JnpfText
                      :textStyle='{"color":"#1684FC","font-weight":"bold","text-decoration":"none","font-size":18,"line-height":32,"font-style":"normal","text-align":"left"}'
                      content="季度进度填报">
                    </JnpfText>
                  </jnpf-form-tip-item>
                </el-col>
              </template>
            </el-form>
            <no_flow_quarterly_progress :key="refreshKey" :proId="this.id"
                                        :projectState="this.list.flowState"
                                        :checkFlowState="checkAcceptFlowState"
                                        :proInfo="this.list" v-if="this.list.id"></no_flow_quarterly_progress>

          </div>
        </div>

        <JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh"/>
        <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download"/>
        <print-browse :visible.sync="printBrowseVisible" :id="printIdNow" :batchIds="multipleSelection.join()"/>
        <PrintDialog v-if="printDialogVisible" ref="printDialog" @change="printBrowseHandle"/>
        <FlowBox v-if="flowVisible" ref="FlowBox" @close="colseFlow"/>
        <el-dialog title="请选择流程" :close-on-click-modal="false" append-to-body
                   :visible.sync="flowListVisible" class="JNPF-dialog template-dialog JNPF-dialog_center"
                   lock-scroll width="400px">
          <el-scrollbar class="template-list">
            <div class="template-item" v-for="item in flowList" :key="item.id"
                 @click="selectFlow(item)">{{ item.fullName }}
            </div>
          </el-scrollbar>
        </el-dialog>
        <ImportBox v-if="uploadBoxVisible" ref="UploadBox" @refresh="initData"/>
        <Detail v-if="detailVisible" ref="Detail" @refresh="detailVisible=false"/>
        <ToFormDetail v-if="toFormDetailVisible" ref="toFormDetail" @close="toFormDetailVisible = false"/>
        <SuperQuery v-if="superQueryVisible" ref="SuperQuery" :columnOptions="superQueryJson"
                    @superQuery="superQuery"/>
      </div>
    </div>
  </transition>
</template>

<script>
import PrintDialog from "@/components/PrintDialog";
import PrintBrowse from "@/components/PrintBrowse/batch";
import request from '@/utils/request'
import {mapGetters} from "vuex";
import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
import {getFormById} from '@/api/workFlow/FormDesign'
import {getFlowList} from '@/api/workFlow/FlowEngine'
import FlowBox from '@/views/workFlow/components/FlowBox'
import ExportBox from '@/components/ExportBox'
import ToFormDetail from '@/views/basic/dynamicModel/list/detail'
import {getDataInterfaceRes} from '@/api/systemData/dataInterface'
import {getConfigData} from '@/api/onlineDev/visualDev'
import {getDefaultCurrentValueUserIdAsync} from '@/api/permission/user'
import {getDefaultCurrentValueDepartmentIdAsync} from '@/api/permission/organize'
import columnList from './columnList'
import {thousandsFormat} from "@/components/Generator/utils/index"
import SuperQuery from '@/components/SuperQuery'
import superQueryJson from './superQueryJson'
import project_quarterly_progress from '../fz_project_quarterly_progress'
import no_flow_quarterly_progress from '../fz_no_flow_project_quarterly_progress'
import axios from "axios";
import comMixin from "@/views/workFlow/workFlowForm/mixin";
import checkAcceptColumnList from '../fz_company_acceptance_apply/columnList'


export default {
  components: {
    FlowBox,
    PrintBrowse,
    PrintDialog,
    ExportBox,
    ToFormDetail,
    SuperQuery,
    project_quarterly_progress,
    no_flow_quarterly_progress
  },
  data() {
    return {
      projectStatus: undefined,
      id: '',
      manageVisible: false,
      refreshKey: 0,// 设置一个 key 用于触发子组件的重新渲染
      isAllPassQuarterly: undefined,
      isCreate: undefined,
      loading: false,
      formRef: 'projectInfoForm',
      printDialogVisible: false,
      printBrowseVisible: false,
      printId: '530664214025472453',
      printIdNow: '530664214025472453',
      keyword: '',
      expandsTree: true,
      refreshTree: true,
      toFormDetailVisible: false,
      expandObj: {},
      columnOptions: [],
      columnCheckAcceptOptions: [],
      mergeList: [],
      exportList: [],
      columnList,
      checkAcceptColumnList,
      superQueryVisible: false,
      superQueryJson,
      uploadBoxVisible: false,
      detailVisible: false,
      query: {
        enterpriseCreditCode: undefined,
        id: undefined,
      },
      treeProps: {
        children: 'children',
        label: 'fullName',
        value: 'id',
        isLeaf: 'isLeaf'
      },
      list: {},
      listLoading: true,
      multipleSelection: [],
      total: undefined,
      queryData: {},
      listQuery: {
        superQueryJson: '',
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime",
      },
      checkAcceptExpandObj: {},
      checkAcceptQueryData: {},
      checkAcceptlistQuery: {
        superQueryJson: '',
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime",
      },
      checkAcceptQuery: {
        projectId: undefined,
        enterpriseCreditCode: undefined,
      },
      checkAcceptFlowState: undefined,
      checkAcceptList: [],
      checkAcceptTotal: undefined,
      checkAcceptFlowList: [],
      formVisible: false,
      flowVisible: false,
      flowListVisible: false,
      flowList: [],
      exportBoxVisible: false,
      aftertransformationDigitalLevelOptions: [{"fullName": "无等级", "id": "0"}, {
        "fullName": "一级",
        "id": "1"
      }, {"fullName": "二级", "id": "2"}, {"fullName": "三级", "id": "3"}, {"fullName": "四级", "id": "4"}],
      aftertransformationDigitalLevelProps: {"label": "fullName", "value": "id"},
      isLoanOptions: [{"fullName": "是", "id": "1"}, {"fullName": "否", "id": "0"}],
      isLoanProps: {"label": "fullName", "value": "id"},
      interfaceRes: {},
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
    menuId() {
      return this.$route.meta.modelId || ''
    }
  },
  watch: {},
  created() {
    // this.selectSelfProject();
    // this.selectQuarterlyStatus();
    this.selectCheckAccept()
    getFormById("530399278779075013").then(res1 => {
      let flowId = res1.data && res1.data.id
      getFlowList(flowId, '1').then(res2 => {
        this.flowList = res2.data
        this.getColumnList(),
          // this.initSearchDataAndListData()
          this.queryData = JSON.parse(JSON.stringify(this.query))
      }).catch((e) => {
        this.$message({type: 'error', message: e.message});
        this.$router.push('/404');
      })
    })
    getFormById("566267928102570309").then(res1 => {
      let flowId = res1.data && res1.data.id
      this.checkAcceptQuery.enterpriseCreditCode = this.userInfo.userAccount
      getFlowList(flowId, '1').then(res2 => {
        this.checkAcceptFlowList = res2.data
        this.getCheckAcceptColumnList(),
          this.initCheckAcceptSearchDataAndListData()
        this.checkAcceptQueryData = JSON.parse(JSON.stringify(this.checkAcceptQuery))
      }).catch((e) => {
        this.$message({type: 'error', message: e.message});
        this.$router.push('/404');
      })
    })
  },
  methods: {
    goBack() {
      this.$emit('refresh')
    },
    refreshComplete() {
      this.selectCheckAccept()
    },
    //查询当前企业的季度进度填报是都审核通过或终止
    selectQuarterlyStatus() {
      const userId = this.userInfo.userAccount;
      const url = `http://test-fzzxqy.demo-caii.com/cloud-api2/fzzxqy/selectQuarterlyProgressByUserId?userId=${userId}`;
      axios.get(url).then(res => {
        this.isAllPassQuarterly = res.data.data
      })
    },
    //项目验收新增和编辑,带有Check的都为项目验收相关方法
    addOrUpdateCheckHandle(row, flowState) {
      if (!row) {
        this.addCheckHandle();
      } else {
        this.updateCheckHandle()
      }
    },
    addCheckHandle() {
      if (!this.checkAcceptFlowList.length) {
        this.$message({type: 'error', message: '流程不存在'});
      } else if (this.checkAcceptFlowList.length === 1) {
        this.selectFlow(this.checkAcceptFlowList[0])
      } else {
        this.flowListVisible = true
      }
    },
    updateCheckHandle(row, flowState) {
      let data = {
        id: row.id,
        flowId: row.flowId || this.checkAcceptFlowList[0].id,
        opType: flowState ? 0 : '-1',
        status: flowState
      }
      this.flowVisible = true
      this.$nextTick(() => {
        this.$refs.FlowBox.init(data)

      })
    },
    selectCheckAccept() {
      this.checkAcceptQuery.enterpriseCreditCode = this.userInfo.userAccount
      this.checkAcceptlistQuery.currentPage = 1
      this.checkAcceptlistQuery.pageSize = 20
      this.checkAcceptlistQuery.sort = "desc"
      this.checkAcceptlistQuery.sidx = "creatortime"
      let _query = {
        ...this.checkAcceptlistQuery,
        ...this.checkAcceptQuery,
        keyword: '',
        dataType: 0,
        menuId: '533184997339693701',
        moduleId: '566267928102570309',
        type: 1,
      };
      request({
        url: `/api/example/Fz_company_acceptance_apply/getList`,
        method: 'post',
        data: _query
      }).then(res => {
        var _list = res.data.list;
        this.checkAcceptList = _list.map(o => ({
          ...o,
          ...this.checkAcceptExpandObj,
        }))
        if (res.data.pagination.total > 0) {
          this.checkAcceptFlowState = this.checkAcceptList[0].flowState;
        }
        this.checkAcceptTotal = res.data.pagination.total
      })
    },
    getCheckAcceptColumnList() {
      // 没有开启权限
      this.columnCheckAcceptOptions = this.checkAcceptTransformColumnList(this.checkAcceptColumnList)
    },
    checkAcceptTransformColumnList(columnList) {
      let list = []
      for (let i = 0; i < columnList.length; i++) {
        const e = columnList[i];
        if (!e.prop.includes('-')) {
          list.push(e)
        } else {
          let prop = e.prop.split('-')[0]
          let label = e.label.split('-')[0]
          let vModel = e.prop.split('-')[1]
          let newItem = {
            align: "center",
            jnpfKey: "table",
            prop,
            label,
            children: []
          }
          e.vModel = vModel
          if (!this.checkAcceptExpandObj.hasOwnProperty(`${prop}Expand`)) this.$set(this.checkAcceptExpandObj, `${prop}Expand`, false)
          if (!list.some(o => o.prop === prop)) list.push(newItem)
          for (let i = 0; i < list.length; i++) {
            if (list[i].prop === prop) {
              list[i].children.push(e)
              break
            }
          }
        }
      }
      this.getMergeList(list)
      this.getExportList(list)
      return list
    },
    async initCheckAcceptSearchDataAndListData() {
      await this.initSearchData()
      this.selectCheckAccept()
    },
    selectSelfProject() {
      this.search()
    },
    printBrowseHandle(id) {
      this.printDialogVisible = false;
      this.handleBatchPrint(id);
    },
    printDialog() {
      if (!this.multipleSelection.length) {
        this.$message({
          type: "warning",
          message: "请选择一条数据",
          duration: 1500
        });
        return;
      }
      this.printDialogVisible = true;
      this.$nextTick(() => {
        if (this.printId.length == 1) {
          this.printBrowseHandle(this.printId[0].id);
          return;
        }
        this.$refs.printDialog.init(this.printId.split(","));
      });
    },
    handleBatchPrint(id) {
      if (!id) {
        this.$message({
          type: "warning",
          message: "请配置打印模板",
          duration: 1500
        });
        return;
      }
      this.printIdNow = id;
      this.printBrowseVisible = true;
    },
    toDetail(defaultValue, modelId) {
      if (!defaultValue) return
      getConfigData(modelId).then(res => {
        if (!res.data || !res.data.formData) return
        let formData = JSON.parse(res.data.formData)
        formData.popupType = 'general'
        this.toFormDetailVisible = true
        this.$nextTick(() => {
          this.$refs.toFormDetail.init(formData, modelId, defaultValue)
        })
      })
    },
    toggleTreeExpand(expands) {
      this.refreshTree = false
      this.expandsTree = expands
      this.$nextTick(() => {
        this.refreshTree = true
        this.$nextTick(() => {
          this.$refs.treeBox.setCurrentKey(null)
        })
      })
    },
    filterNode(value, data) {
      if (!value) return true;
      return data[this.treeProps.label].indexOf(value) !== -1;
    },
    loadNode(node, resolve) {
      const nodeData = node.data
      const config = {
        treeInterfaceId: "",
        treeTemplateJson: []
      }
      if (config.treeInterfaceId) {
        //这里是为了拿到参数中关联的字段的值，后端自行拿
        if (config.treeTemplateJson && config.treeTemplateJson.length) {
          for (let i = 0; i < config.treeTemplateJson.length; i++) {
            const element = config.treeTemplateJson[i];
            element.defaultValue = nodeData[element.relationField] || ''
          }
        }
        //参数
        let query = {
          paramList: config.treeTemplateJson || [],
        }
        //接口
        getDataInterfaceRes(config.treeInterfaceId, query).then(res => {
          let data = res.data
          if (Array.isArray(data)) {
            resolve(data);
          } else {
            resolve([]);
          }
        })
      }
    },
    getColumnList() {
      // 没有开启权限
      this.columnOptions = this.transformColumnList(this.columnList)
    },
    transformColumnList(columnList) {
      let list = []
      for (let i = 0; i < columnList.length; i++) {
        const e = columnList[i];
        if (!e.prop.includes('-')) {
          list.push(e)
        } else {
          let prop = e.prop.split('-')[0]
          let label = e.label.split('-')[0]
          let vModel = e.prop.split('-')[1]
          let newItem = {
            align: "center",
            jnpfKey: "table",
            prop,
            label,
            children: []
          }
          e.vModel = vModel
          if (!this.expandObj.hasOwnProperty(`${prop}Expand`)) this.$set(this.expandObj, `${prop}Expand`, false)
          if (!list.some(o => o.prop === prop)) list.push(newItem)
          for (let i = 0; i < list.length; i++) {
            if (list[i].prop === prop) {
              list[i].children.push(e)
              break
            }
          }
        }
      }
      this.getMergeList(list)
      this.getExportList(list)
      return list
    },
    arraySpanMethod({column}) {
      for (let i = 0; i < this.mergeList.length; i++) {
        if (column.property == this.mergeList[i].prop) {
          return [this.mergeList[i].rowspan, this.mergeList[i].colspan]
        }
      }
    },
    getMergeList(list) {
      let newList = JSON.parse(JSON.stringify(list))
      newList.forEach(item => {
        if (item.children && item.children.length) {
          let child = {
            prop: item.prop + '-child-first'
          }
          item.children.unshift(child)
        }
      })
      newList.forEach(item => {
        if (item.children && item.children.length) {
          item.children.forEach((child, index) => {
            if (index == 0) {
              this.mergeList.push({
                prop: child.prop,
                rowspan: 1,
                colspan: item.children.length
              })
            } else {
              this.mergeList.push({
                prop: child.prop,
                rowspan: 0,
                colspan: 0
              })
            }
          })
        } else {
          this.mergeList.push({
            prop: item.prop,
            rowspan: 1,
            colspan: 1
          })
        }
      })
    },
    getExportList(list) {
      let exportList = []
      for (let i = 0; i < list.length; i++) {
        if (list[i].jnpfKey === 'table') {
          for (let j = 0; j < list[i].children.length; j++) {
            exportList.push(list[i].children[j])
          }
        } else {
          exportList.push(list[i])
        }
      }
      this.exportList = exportList
    },
    goDetail(id) {
      this.detailVisible = true
      this.$nextTick(() => {
        this.$refs.Detail.init(id)
      })
    },
    sortChange({column, prop, order}) {
      this.listQuery.sort = order == 'ascending' ? 'asc' : 'desc'
      this.listQuery.sidx = !order ? '' : prop
      this.initData(this.id)
    },
    async initSearchDataAndListData() {
      await this.initSearchData()
      this.initData(this.id)
    },
    //初始化查询的默认数据
    async initSearchData() {
    },
    initData(id, projectStatus) {
      this.projectStatus = projectStatus
      this.id = id;
      this.query.id = id
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        keyword: this.keyword,
        dataType: 0,
        menuId: this.menuId,
        moduleId: '530399278779075013',
        type: 1,
      };
      request({
        url: `/api/example/Fz_project_filing/getList`,
        method: 'post',
        data: _query
      }).then(res => {
        this.list = {...res.data.list[0], ...this.expandObj};
        this.listLoading = false
      })
    },
    handleDel(id) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        type: 'warning'
      }).then(() => {
        request({
          url: `/api/example/Fz_project_filing/${id}`,
          method: 'DELETE'
        }).then(res => {
          this.$message({
            type: 'success',
            message: res.msg,
            onClose: () => {
              this.initData(this.id)
            }
          });
        })
      }).catch(() => {
      });
    },
    handelUpload() {
      this.uploadBoxVisible = true
      this.$nextTick(() => {
        this.$refs.UploadBox.init("", "example/Fz_project_filing")
      })
    },
    handleSelectionChange(val) {
      const res = val.map(item => item.id)
      this.multipleSelection = res
    },
    handleBatchRemoveDel() {
      if (!this.multipleSelection.length) {
        this.$message({
          type: 'error',
          message: '请选择一条数据',
          duration: 1500,
        })
        return
      }
      const ids = this.multipleSelection
      this.$confirm('您确定要删除这些数据吗, 是否继续？', '提示', {
        type: 'warning'
      }).then(() => {
        request({
          url: `/api/example/Fz_project_filing/batchRemove`,
          data: ids,
          method: 'DELETE'
        }).then(res => {
          this.$message({
            type: 'success',
            message: res.msg,
            onClose: () => {
              this.initData(this.id)
            }
          });
        })
      }).catch(() => {
      })
    },
    openSuperQuery() {
      this.superQueryVisible = true
      this.$nextTick(() => {
        this.$refs.SuperQuery.init()
      })
    },
    superQuery(queryJson) {
      this.listQuery.superQueryJson = queryJson
      this.listQuery.currentPage = 1
      this.initData(this.id)
    },
    addOrUpdateHandle(row, flowState) {
      if (!row) {
        const userId = this.userInfo.userAccount;
        const url = `http://test-fzzxqy.demo-caii.com/cloud-api2/fzzxqy/company_base_main?userId=${userId}`;
        axios.get(url).then(res => {
          if (res.data.data.length === 0) {
            this.$message({
              type: 'warning',
              message: '您的被改造企业申请暂未审核通过或仍未提交！'
            });
          } else {
            if (res.data.data[0].industry === '' || res.data.data[0].industry === null || res.data.data[0].industry === "" || res.data.data[0].industry === undefined) {
              this.$message({
                type: 'warning',
                message: '您的被改造企业申请暂未审核通过或仍未提交！'
              });
            } else {
              this.addHandle();
            }
          }
        })
      } else {
        this.updateHandle(row, flowState)
      }
    },
    exportData() {
      this.exportBoxVisible = true
      this.$nextTick(() => {
        this.$refs.ExportBox.init(this.exportList)
      })
    },
    download(data) {
      let query = {...data, ...this.listQuery, ...this.query, menuId: this.menuId}
      request({
        url: `/api/example/Fz_project_filing/Actions/Export`,
        method: 'post',
        data: query
      }).then(res => {
        if (!res.data.url) return
        this.jnpf.downloadFile(res.data.url)
        this.$refs.ExportBox.visible = false
        this.exportBoxVisible = false
      })
    },
    search() {
      this.listQuery.currentPage = 1
      this.listQuery.pageSize = 20
      this.listQuery.sort = "desc"
      this.listQuery.sidx = "creatortime"
      this.initData(this.id)
    },
    //流程改造后相关调用方法
    updateHandle(row, flowState) {
      let data = {
        id: row.id,
        flowId: row.flowId || this.flowList[0].id,
        opType: flowState ? 0 : '-1',
        status: flowState
      }
      this.flowVisible = true
      this.$nextTick(() => {
        this.$refs.FlowBox.init(data)
      })
    },
    toApprovalDetail(row) {
      let data = {
        id: row.id,
        flowId: row.flowId,
        opType: 0,
        status: row.currentState
      }
      this.formVisible = true
      this.$nextTick(() => {
        this.$refs.FlowBox.init(data)
      })
    },
    addHandle() {
      if (!this.flowList.length) {
        this.$message({type: 'error', message: '流程不存在'});
      } else if (this.flowList.length === 1) {
        this.selectFlow(this.flowList[0])
      } else {
        this.flowListVisible = true
      }
    },
    //选择流程发起
    selectFlow(item) {
      let data = {
        id: '',
        formType: 1,
        flowId: item.id,
        opType: '-1',
        pageType: '项目备案'
      }
      this.flowListVisible = false
      this.flowVisible = true
      this.$nextTick(() => {
        this.$refs.FlowBox.init(data)
      })
    },
    refresh(isrRefresh) {
      this.formVisible = false
      if (isrRefresh) this.reset()
    },
    reset() {
      this.selectCheckAccept()
      // 点击按钮时更新 key 的值，从而触发子组件的重新渲染
      this.refreshKey++;
      this.query = JSON.parse(JSON.stringify(this.queryData))
      this.search()
    },
    colseFlow(isrRefresh) {
      this.flowVisible = false
      if (isrRefresh) this.reset()
    },
  }
}
</script>
<style lang="scss" scoped>
.project-info {
  position: absolute;
  width: -webkit-fill-available;
  background: #EBEEF5;

  .JNPF-common-layout {
    min-height: 800px;

    ::v-deep .JNPF-common-layout-center {
      height: auto;
      padding: 0 20px;
      background: #F0F4F9;
      width: 100%;
    }
  }

  .project-loop {
    padding: 10px 20px;
    margin: 10px;
    background: #F0F4F9;

    .closeButton {
      position: fixed;
      right: 3%;
      display: block;
      z-index: 99;

      .ym-custom {
        font-size: 35px;
      }
    }

    .project-main {
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1) !important;
      border: 1px solid #EBEEF5;
      padding: 30px 30px 10px 30px;
      border-radius: 5px;
      background: #FFFFFF;

      .el-row .el-col .el-form-item--mini {
        display: flex;
        flex-direction: row;

        ::v-deep .el-form-item__label {
          width: 75px;
        }


        ::v-deep .el-form-item__content {
          width: calc(100% - 80px);
        }
      }

      ::v-deep .el-col:nth-child(2) {
        .el-form-item__label {
          width: 105px !important;
        }

        .el-form-item__content {
          width: calc(100% - 110px) !important;
        }
      }
    }

    .project-flow-main {
      .el-col {
        display: flex;
        flex-direction: column;
        padding: 15px 22px;
        border: 1px solid #BBBBBB;
        border-radius: 0 50px;
        box-shadow: 0px 10px 10px 0px rgba(0, 0, 0, 0.2);
        background: linear-gradient(to right top, #F8FEF9, #FFFFFF);
        width: 23%;
        margin: 0 1%;

        .flow-step {
          height: 30px;
          display: flex;
          flex-direction: row;

          i {
            font-size: 22px;
            line-height: 30px;
          }

          label {
            margin-left: 10px;
            font-size: 16px;
            line-height: 30px;
          }
        }

        .flow-controller {
          margin: 5px 5px 5px 20px;
          line-height: 38px;

          label {
            font-size: 18px;
            font-weight: bold;
          }

          .el-button {
            float: right;
            width: 74px;
            height: 33px;
            background: linear-gradient(to right, #1890FF, #3FB9F1);
          }
        }

        .flow-result {

          .flow-ing {
            color: #337CCE;
          }

          .el-alert {
            background-color: transparent;
            box-shadow: none;
            padding: 5px 16px;

            ::v-deep .el-alert__icon {
              font-size: 18px;
              margin-right: 3px;
            }

            ::v-deep .el-alert__title {
              font-size: 15px;
            }

          }
        }
      }
    }
  }
}
</style>
